//
//  OtherChatCell.swift
//  AESOLAR_IOS
//
//  Created by Mr.Wang on 2019/10/16.
//  Copyright © 2019 Mr.Wang. All rights reserved.
//

import UIKit

class OtherChatCell: UITableViewCell {

    let chatBackgroundView = UIView()
    let contentLabel = UILabel()
    let timeLabel = UILabel()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = UIColor.clear
        
        timeLabel.textColor = #colorLiteral(red: 0.6901960784, green: 0.6901960784, blue: 0.6901960784, alpha: 1)
        timeLabel.font = UIFont.systemFont(ofSize: 12)
        self.addSubview(timeLabel)
        timeLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.centerY.equalTo(self.snp.top).offset(20)
        }
        
        chatBackgroundView.layer.cornerRadius = 10
        chatBackgroundView.backgroundColor = .white
        self.addSubview(chatBackgroundView)
        chatBackgroundView.snp.makeConstraints { (make) in
            make.top.equalTo(40)
            make.bottom.equalTo(-18)
            make.right.lessThanOrEqualTo(-15)
            make.left.equalTo(15)
        }
        
        UIImageView().config
            .image(UIImage.init(named: "other_chat_indicator"))
            .addTo(self)
            .makeConstraints { (make) in
                make.top.equalTo(chatBackgroundView.snp.bottom)
                make.left.equalTo(chatBackgroundView.snp.left)
                make.width.equalTo(12)
                make.height.equalTo(8)
        }
        
        UIView().config.backgroundColor(.white)
            .addTo(self)
            .makeConstraints { (make) in
                make.bottom.equalTo(chatBackgroundView.snp.bottom)
                make.left.equalTo(chatBackgroundView.snp.left)
                make.width.height.equalTo(15)
        }
        
        contentLabel.textColor = #colorLiteral(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)
        contentLabel.numberOfLines = 0
        contentLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        chatBackgroundView.addSubview(contentLabel)
        contentLabel.snp.makeConstraints { (make) in
            make.left.top.equalTo(15)
            make.bottom.right.equalTo(-15)
        }
    }
    
    func bind(_ layout: ChatLayoutModel) {
        contentLabel.text = layout.model.content
        timeLabel.text = layout.model.createTime
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
